package com.pay.web.utils;
import  java.util.*;
/**
 * Created by chenweiyi on 2018/2/5.
 */
public class ResultUtils {


    /**
     * 转换结果
     * @param code
     * @param description
     * @return
     */
    public static Map<String,Object> parseResult(String code,String description,Object data){
        Map<String,Object> result = new HashMap<String,Object>();

        result.put("code",code);
        result.put("description",description);
        if(data != null){
            Map<String,Object > temp = WebUtils.objectToMap(data);
            if(temp != null){
                Iterator<Map.Entry<String,Object>> iterator = temp.entrySet().iterator();
                while(iterator.hasNext()){
                    Map.Entry<String,Object> entry =  iterator.next();
                    result.put(entry.getKey(),entry.getValue());
                }
            }
        }
        return result;

    }

    /**
     * 操作成功
     * @param data
     * @return
     */
    public static Map<String,Object> parseSuccess(Object data){
        return parseResult("success","操作成功",data);
    }

    /**
     * 操作失败
     * @param code
     * @param description
     * @return
     */
    public static Map<String,Object> parseFailure(String code,String description){
        return parseResult(code,description,null);
    }
}
